{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 使用数组的索引和切片，掌握数组数值修改",
   "id": "6a0fe7a48bd9bde4"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-02-27T00:39:28.604285Z",
     "start_time": "2025-02-27T00:39:28.454510Z"
    }
   },
   "source": "import numpy as np",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-27T00:39:28.607707Z",
     "start_time": "2025-02-27T00:39:28.604285Z"
    }
   },
   "cell_type": "code",
   "source": [
    "array_1 = np.arange(24).reshape(4, 6)\n",
    "print(array_1)"
   ],
   "id": "332b7d3d22edf4aa",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-27T00:39:28.611835Z",
     "start_time": "2025-02-27T00:39:28.607707Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 切片\n",
    "print(array_1[0:2, 3:4])\n",
    "print(array_1[:,1:3])   # 返回轴0的所有元素，轴1的第1到第2\n",
    "print(array_1[0:2,:])"
   ],
   "id": "8e08e15c86c1897d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3]\n",
      " [9]]\n",
      "[[ 1  2]\n",
      " [ 7  8]\n",
      " [13 14]\n",
      " [19 20]]\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]]\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-27T00:39:28.617755Z",
     "start_time": "2025-02-27T00:39:28.611835Z"
    }
   },
   "cell_type": "code",
   "source": "print(array_1[[2],[3]])",
   "id": "fc6a0b0efaa11825",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[15]\n"
     ]
    }
   ],
   "execution_count": 5
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
